<template>
  <div class="contents">
    <!-- 查询条件 -->
    <el-form :inline="true" :model="pageInfo" size="mini">
      <el-form-item label="业主名称">
        <el-select
          v-model="pageInfo.region"
          placeholder="选择业主名称"
          @keyup.enter.native="handleQuery"
        >
          <el-option label="区域一" value="shanghai"></el-option>
          <el-option label="区域二" value="beijing"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="登记人">
        <el-select
          v-model="pageInfo.allocation"
          placeholder="选择登记人"
          @keyup.enter.native="handleQuery"
        >
          <el-option label="区域一" value="shanghai"></el-option>
          <el-option label="区域二" value="beijing"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="维修状态">
        <el-select
          v-model="pageInfo.branch"
          placeholder="选择维修状态"
          @keyup.enter.native="handleQuery"
        >
          <el-option label="区域一" value="shanghai"></el-option>
          <el-option label="区域二" value="beijing"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="维修日期">
        <el-select
          v-model="pageInfo.branch"
          placeholder="选择维修日期"
          @keyup.enter.native="handleQuery"
        >
          <el-option label="区域一" value="shanghai"></el-option>
          <el-option label="区域二" value="beijing"></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="生成时间">
        <el-select
          v-model="pageInfo.generated"
          placeholder="选择生成时间"
          @keyup.enter.native="handleQuery"
        >
          <el-option label="区域一" value="shanghai"></el-option>
          <el-option label="区域二" value="beijing"></el-option>
        </el-select>
      </el-form-item> -->
    </el-form>
    <!-- 按钮操作 -->
    <div class="operation">
      <!-- 新增数据 -->
      <div class="operator" @click="add">
        <img
          src="@/assets/svg/insert-button.svg"
          alt=""
          width="20px"
          height="20px"
        />
        <p>新增数据</p>
      </div>
      <!-- 批量删除 -->
      <div class="operator" @click="deletebatches">
        <img
          src="@/assets/svg/batch-delete-button.svg"
          alt=""
          width="20px"
          height="20px"
        />
        <p>批量删除</p>
      </div>
      <!-- 导出数据 -->
      <div class="operator" @click="print">
        <img src="@/assets/svg/导出.svg" alt="" width="20px" height="20px" />
        <p>导出数据</p>
      </div>
      <el-button size="small" @click="resetform">重置</el-button>
      <el-button size="small" type="primary" @click="handleQuery"
        >查询</el-button
      >
    </div>
    <!-- 表格数据 -->
    <div class="tables">
      <el-table
        :data="tableData"
        border
        size="mini"
        stripe
        height="100%"
        style="width: 100%; margin-top: 30px"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" />
        <el-table-column label="序号" width="70" align="center">
          <template slot-scope="scope">
            {{ (pageInfo.pageNo - 1) * pageInfo.pageSize + scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column prop="data" align="center" label="业主" width="200">
        </el-table-column>
        <el-table-column
          prop="data"
          align="center"
          label="故障信息"
          width="350"
        >
        </el-table-column>
        <el-table-column prop="data" align="center" label="登记人" width="200">
        </el-table-column>
        <el-table-column
          prop="data"
          align="center"
          label="维修日期"
          width="200"
        >
        </el-table-column>
        <el-table-column
          prop="data"
          align="center"
          label="所属小组"
          width="200"
        >
        </el-table-column>
        <el-table-column
          prop="data"
          align="center"
          label="维修状态"
          width="200"
        >
        </el-table-column>
        <!-- <el-table-column
          prop="data"
          align="center"
          label="生成时间"
          width="200"
        >
        </el-table-column> -->
        <el-table-column label="操作" width="200" align="center" fixed="right">
          <template v-slot="{ row }">
            <!-- <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="edit(row.id)"
              title="修改"
            /> -->
            <el-button
              type="warning"
              icon="el-icon-finished"
              size="mini"
              @click="audit(row.id)"
              title="详情"
            />
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="removeDataById(row.id)"
              style="margin-left: 30px"
              title="删除"
            />
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页查询 -->
    <div class="pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageInfo.pageNo"
        :page-sizes="[15, 30, 50, 100]"
        :page-size="pageInfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageInfo.total"
      >
      </el-pagination>
    </div>
    <!-- 详情页面 -->
    <el-dialog
      :title="form.id ? '维保信息修改' : '维保信息录入'"
      :visible.sync="dialogVisible"
      width="35%"
    >
      <!-- :rules="rules" -->
      <el-form
        ref="form"
        :model="form"
        label-width="90px"
        size="small"
        label-position="left"
      >
        <div style="display: flex">
          <el-form-item
            label="业主名称"
            prop="deviceName"
            style="flex: 1; margin-right: 5px"
          >
            <el-input
              placeholder="请选择业主"
              v-model="form.deviceName"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="维修状态" style="flex: 1; margin-left: 5px">
            <el-input
              placeholder="请选择维修状态"
              v-model="form.deviceName"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </div>
        <div style="display: flex">
          <el-form-item label="故障信息" style="flex: 1; margin-right: 5px">
            <el-input
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 6 }"
              placeholder="请输入故障信息"
              v-model="form.textarea2"
            >
            </el-input>
          </el-form-item>
          <el-form-item label="维修方案" style="flex: 1; margin-left: 5px">
            <el-input
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 6 }"
              placeholder="请输入维修方案"
              v-model="form.textarea2"
            >
            </el-input>
          </el-form-item>
        </div>
        <el-form-item label="维修前图片">
          <el-upload
            class="upload-demo"
            action="https://jsonplaceholder.typicode.com/posts/"
            :on-change="handleChange"
            :file-list="form.fileList"
            list-type="picture"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">
              只能上传jpg/png文件，且不超过500kb
            </div>
          </el-upload>
        </el-form-item>
        <el-form-item label="维修后图片">
          <el-upload
            class="upload-demo"
            action="https://jsonplaceholder.typicode.com/posts/"
            :on-change="handleChange"
            :file-list="form.followup"
            list-type="picture"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">
              只能上传jpg/png文件，且不超过500kb
            </div>
          </el-upload>
        </el-form-item>
        <div style="display: flex">
          <el-form-item label="维修总价" style="flex: 1; margin-left: 5px">
            <el-input
              placeholder="请输入总价格"
              v-model="form.deviceName"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="报价明细" style="flex: 1; margin-left: 5px">
            <el-button type="primary" @click="innerVisible = true"
              >添加明细</el-button
            >
          </el-form-item>
        </div>

        <el-table :data="detailformData" border size="mini" style="width: 100%">
          <el-table-column align="center" prop="data" label="项目" width="140">
          </el-table-column>
          <el-table-column align="center" prop="data" label="数量" width="70">
          </el-table-column>
          <el-table-column align="center" prop="data" label="单价" width="70">
          </el-table-column>
          <el-table-column align="center" prop="data" label="总价" width="70">
          </el-table-column>
          <el-table-column align="center" prop="data" label="备注">
          </el-table-column>
          <el-table-column
            label="操作"
            width="100"
            align="center"
            fixed="right"
          >
            <template v-slot="{ row }">
              <el-button size="small" type="text" @click="offermod(row.id)">
                修改</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer">
        <el-button size="small" @click="dialogVisible = false">取 消</el-button>
        <el-button size="small" type="primary" @click="save">确 定</el-button>
      </div>
      <!-- 明细添加 -->
      <el-dialog
        :title="form.id ? '报价明细修改' : '报价明细录入'"
        :visible.sync="innerVisible"
        width="20%"
        append-to-body
      >
        <!-- :rules="rules" -->
        <el-form
          ref="detailform"
          :model="detailform"
          label-width="50px"
          size="small"
          label-position="left"
        >
          <el-form-item label="项目">
            <el-input
              placeholder="请选择项目"
              v-model="form.deviceName"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="数量">
            <el-input
              placeholder="请输数量"
              v-model="form.deviceName"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="单价">
            <el-input
              placeholder="请输入单价"
              v-model="form.deviceName"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="总价">
            <el-input
              placeholder="请输价格"
              v-model="form.deviceName"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="备注">
            <el-input
              placeholder="请输入现场基本情况"
              v-model="form.deviceName"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer">
          <el-button size="small" type="primary" @click="detailsave"
            >确 定</el-button
          >
        </div>
      </el-dialog>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'mainstate',
  data() {
    return {
      //搜索表单数据
      pageInfo: {
        // 总条数
        total: 0,
        // 当前页
        pageNo: 1,
        // 每页条数
        pageSize: 15,
        region: '',
        allocation: '',
        branch: '',
        performance: '',
        generated: ''
      },
      // 表格数据
      tableData: [{ data: '分过无痕' }],
      // 表单明细数据
      detailformData: [{ data: '分过无痕' }],
      // 详情开关
      dialogVisible: false,
      // 报价明细开关
      innerVisible: false,
      // 多选数组
      selectValue: [],
      // 表单数据
      form: {},
      // 报价明细表单数据
      detailform: {}
    }
  },
  created() {},
  methods: {
    // 查询数据
    tableDatalist() {},
    // 详情按钮
    audit() {
      this.dialogVisible = true
    },
    // 删除按钮
    removeDataById(id) {
      console.log('删除id', id)
    },
    // 重置按钮
    resetform() {},
    // 查询按钮
    handleQuery() {
      console.log('查询了')
    },
    // 文件上传钩子
    handleChange(file, fileList) {
      console.log('文件上传', file)
      console.log('文件上传', fileList)
    },
    // 添加数据
    add() {
      this.dialogVisible = true
    },
    // 添加确认按钮
    save() {},
    // 报价明细添加
    offermod(id) {
      this.innerVisible = true
    },
    // 报价明细确认按钮
    detailsave() {},
    // 导出按钮
    print() {},
    // 批量删除
    deletebatches() {
      // 判断是否选中
      if (this.selectValue.length == 0) {
        this.$message.warning('请选择要删除的数据！')
        return
      }
      // 删除操作
      this.$confirm('确定删除这条数据', '删除')
        .then(async () => {
          //数组
          var idList = []
          this.selectValue.forEach((item) => {
            console.log(item)
            let id = item.id
            idList.push(id)
          })
          console.log('删除数据id', idList)
          // 发请求删除数据
          //   const res = await perdeleteList(idList);
          //   console.log("批量删除", res);
          // 提示信息
          this.$message.success(res.message)
          // 刷新数据
          //   this.tableDatalist();
        })
        .catch(() => {})
    },
    //复选框发生变化执行方法
    handleSelectionChange(selection) {
      this.selectValue = selection
      //console.log(this.selectValue)
    },
    // 分页 左右 点击 输入
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pageInfo.pageSize = val
      this.tableDatalist()
    },
    // 分页多少条点击事件
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.pageInfo.pageNo = val
      this.tableDatalist()
    }
  }
}
</script>

<style lang="scss" scoped>
.contents {
  height: 847px;
  margin: 20px;
  overflow: hidden;
  padding-top: 10px;
  //   background-color: skyblue;
  // 适配谷歌火狐，没有书签栏的上下边距
  @media screen and (min-height: 950px) and (max-height: 990px) {
    margin: 36px 20px;
  }
  // 适配浏览器全屏模式下的上下边距
  @media screen and (min-height: 1070px) {
    margin: 40px 20px;
  }
  // 按钮操作
  .operation {
    width: 650px;
    margin-bottom: 30px;
    margin-top: 10px;
    float: right;
    display: flex;
    align-items: center;
    justify-content: space-around;
    // background-color: skyblue;
    @media screen and (min-height: 1070px) {
      margin: 28px 0;
    }
    .operator {
      width: 110px;
      height: 32px;
      display: flex;
      justify-content: space-around;
      align-items: center;
      cursor: pointer;
      &:hover {
        border: 1px solid #08090a;
        border-radius: 3px;
      }
    }
    //修改饿了么按钮的样式
    ::v-deep .el-button {
      width: 110px;
      border: 1px solid #08090a;
    }
  }
  // 表格数据
  .tables {
    width: 100%;
    height: 535px;
    @media screen and (min-height: 1070px) {
      height: 685px;
    }
  }
  .pagination {
    // background-color: skyblue;
    position: fixed;
    bottom: 50px;
    right: 120px;
    // 适配浏览器全屏模式下的上下边距
    @media screen and (min-height: 1070px) {
      bottom: 65px;
    }
  }
}
</style>